Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
mongodb update fails due to _id without the "ObjectId" text

I have a script that identified two records that I need to update. My query returned the two _id values as: 62bdca65a69a2cdf17978992 and 62c06c18d694a13c4a29c078. I generated update the statements:

db.people.updateOne({_id: ObjectId('62bdca65a69a2cdf17978992')}, {$set: {dept: 22}});
db.people.updateOne({_id: ObjectId('62c06c18d694a13c4a29c078')}, {$set: {dept: 22}});

Only one got updated and examination of the data showed that one has the _id: 62bdca65a69a2cdf17978992 and the other has the _id as ObjectId('62c06c18d694a13c4a29c078').

  1. Can I somehow determine if the "ObjectId" part of the _id exists so that I can dynamically include or exclude that in my update?
  2. Can I write the update statement in a generic way so both get updated?
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!